package com.handpay.nocardpay.baselibrary.main.mine.view.fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.handpay.nocardpay.baselibrary.R;
import com.handpay.nocardpay.baselibrary.commbase.view.fragment.BaseFragment;
import com.handpay.nocardpay.baselibrary.main.mine.MainFragment;
import com.handpay.nocardpay.baselibrary.qualificationinfo.view.fragment.QualificationBaseInfoFragment;
import com.handpay.nocardpay.baselibrary.qualificationinfo.view.fragment.QualificationStatuInfoFragment;
import com.handpay.nocardpay.baselibrary.utils.AccountUtils;
import com.handpay.nocardpay.baselibrary.utils.ClientEngine;
import com.handpay.nocardpay.baselibrary.utils.StatusBarUtil;

/**
 * Created by sxshi on 2017/8/13.
 */

public class NoQualificationFragment extends BaseFragment implements View.OnClickListener {
    private Button btn_submit;
    private TextView tv_version;
    private RelativeLayout rl_qualification_fail, rl_qualification_checking;
    private RelativeLayout rl_qualification_nosubmit;

    public static NoQualificationFragment newInstance() {
        Bundle args = new Bundle();
        NoQualificationFragment fragment = new NoQualificationFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_no_qualification;
    }

    @Override
    public void initView(View view) {
        btn_submit = (Button) view.findViewById(R.id.btn_submit);
        tv_version = (TextView) view.findViewById(R.id.tv_version);
        rl_qualification_fail = (RelativeLayout) view.findViewById(R.id.rl_qualification_fail);
        rl_qualification_checking = (RelativeLayout) view.findViewById(R.id.rl_qualification_checking);
        rl_qualification_nosubmit = (RelativeLayout) view.findViewById(R.id.rl_qualification_nosubmit);
    }

    @Override
    public void setStatusBar(View view) {
        
    }

    @Override
    public void onSupportVisible() {
        super.onSupportVisible();
        if (AccountUtils.getAccountStatus(_mActivity) == AccountUtils.AccountStatus.FAIL) {
            rl_qualification_fail.setVisibility(View.VISIBLE);
            rl_qualification_checking.setVisibility(View.GONE);
            rl_qualification_nosubmit.setVisibility(View.GONE);
            StatusBarUtil.setColor(_mActivity, _mActivity.getResources().getColor(R.color.colorFailQua), 0);
        } else if (AccountUtils.getAccountStatus(_mActivity) == AccountUtils.AccountStatus.CHECKING) {
            rl_qualification_checking.setVisibility(View.VISIBLE);
            rl_qualification_nosubmit.setVisibility(View.GONE);
            rl_qualification_fail.setVisibility(View.GONE);
            StatusBarUtil.setColor(_mActivity, _mActivity.getResources().getColor(R.color.colorCheckQua), 0);
        } else {
            rl_qualification_fail.setVisibility(View.GONE);
            rl_qualification_checking.setVisibility(View.GONE);
            rl_qualification_nosubmit.setVisibility(View.VISIBLE);
            StatusBarUtil.setColor(_mActivity, _mActivity.getResources().getColor(R.color.colorPrimaryDark), 0);
        }
    }

    @Override
    public void initListener() {
        btn_submit.setOnClickListener(this);
        rl_qualification_fail.setOnClickListener(this);
        rl_qualification_checking.setOnClickListener(this);
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        tv_version.setText(String.format(_mActivity.getString(R.string.mine_version), ClientEngine.getInstance().VERSION));
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.btn_submit || v.getId() == R.id.rl_qualification_fail) {
            ((MainFragment) (getParentFragment().getParentFragment())).start(QualificationBaseInfoFragment.newInstance());
        } else if (v.getId() == R.id.rl_qualification_checking) {
            ((MainFragment) (getParentFragment().getParentFragment())).start(QualificationStatuInfoFragment.newInstance());
        }
    }
}
